# Contributor: Leonardo Arena <rnalrd@alpinelinux.org>
# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
#
# TODO: Fix init script (remove bashisms)
pkgname=ocfs2-tools
pkgver=1.8.7
pkgrel=4
pkgdesc="Oracle Cluster File System 2 Core Tools"
url="https://ocfs2.wiki.kernel.org"
arch="all"
license="GPL-2.0-only"
depends_dev="$pkgname=$pkgver-r$pkgrel glib-dev"
makedepends="$depends_dev autoconf automake e2fsprogs-dev libaio-dev libtool
	libtirpc-dev linux-headers ncurses-dev readline-dev"
subpackages="$pkgname-dev $pkgname-doc"
source="ocfs2-tools-$pkgver.tar.gz::https://github.com/markfasheh/ocfs2-tools/archive/ocfs2-tools-$pkgver.tar.gz
	o2cb.initd
	o2cb.confd
	cluster.conf
	musl-libocfs2-__bswap_constant_32.patch
	musl-o2info-atimensec.patch
	new-linux.patch
	fix-operations-include-ioctl.patch
	fix-o2monitor-undeclared-PATH_MAX.patch
	tunefs-remove-op_query.patch
	fix-sysmacros.patch
	enable-format-warnings.patch
	fix-implicit-basename.patch
	"
builddir="$srcdir/$pkgname-$pkgname-$pkgver"

prepare() {
	update_config_guess
	update_config_sub
	default_prepare

	./autogen.sh
}

build() {
	# _GNU_SOURCE is needed for loff_t from fcntl.h; it's already defined
	# in many ocfs2-tools' sources, but after fcntl.h is included.
	export CFLAGS="$CFLAGS -D_LARGEFILE64_SOURCE -D_GNU_SOURCE $(pkgconf --cflags libtirpc)"
	export LDFLAGS="$LDFLAGS $(pkgconf --cflags libtirpc)"

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--disable-glibtest \
		--disable-static
	make -j1
}

package() {
	# passing prefix to ./configure doesn't actually set the sbin dir correctly,
	# but passing it to make does...
	make DESTDIR="$pkgdir" sbindir=/usr/sbin install
	rm -f  "$pkgdir"/usr/lib/*.a

	# FIXME: remove bashisms
	#install -m 755 -D "$srcdir"/o2cb.initd "$pkgdir"/etc/init.d/o2cb
	#install -m 644 -D "$srcdir"/o2cb.confd "$pkgdir"/etc/conf.d/o2cb
	install -m 644 -D "$srcdir"/cluster.conf "$pkgdir"/etc/ocfs2/cluster.conf
}

sha512sums="
10246ccb53ec1da59f2117f047bd8a9d7b4e5471e01dd262e8a694b530be2356d843f8faa6cf559f24ca39db45572d57540ee49a373b7658db23ff08c22541bb  ocfs2-tools-1.8.7.tar.gz
9baf076d315348d3c280f17a126196bd7f1f758a9de536b3eb08e8fb01afa2df04b6a658039d5694212e8d5f6109fc3db45c421e4b20d4678646caf547e2aa4b  o2cb.initd
e510f08a9adc2d7c07e7b8a4d2c503c5a130a156ab1bf1cf45d8480dd94490968f718e966d0bae090a883ff36768e17971415f9905bd5dcf8632f16f7c0b931e  o2cb.confd
f844e5389e0b42d6f91a1335bd2ef4d2666e5b883c999d05acd3bc63ad901bc5838aa4da35bb1d069463d7cc7dcfa277dbaa938b5953e8d420a37cfbb30f24f3  cluster.conf
87ea579ddb4a6ae34c5b815fe9015dc0168cb267312f9ef3dccfd16cd65a1f13ef1275dda72308d952ca844e42a486c891340210c4757866f2caacd0d6d3a916  musl-libocfs2-__bswap_constant_32.patch
d1eb24086f71f22e0333f4c246389ce82c9b4540bb0a2d091f6deee7f563c7e5457a838937cd07f1b90359e9c215639aebcbc54c551fb0e9e3617f29c03d49a1  musl-o2info-atimensec.patch
56fa3bdefca7fabec6db1ba24a5b6ee669008f05a953d88f1336a6a74e095235de350bc3adb810ec79d5e2c5045cec0db25ea4eb49e65ac31324dd7e4d770c32  new-linux.patch
41b5e0d2eae738a8e05b6377e6dd4fc79592c6fc7b62dbc1ea6d7bd1fdb80122bc2f915748e64e30c9e964a1ebc73a65d81b5409fd499a959b3015d8c0683ead  fix-operations-include-ioctl.patch
35d5872e6a3651583442b3a333a2e866bf241b4fc19bdbabf4bb46cdbdb6b2806d81092b1fa80a9841a49e95a40d2bc09d12ad33e8cfbf3c267698eb9120b307  fix-o2monitor-undeclared-PATH_MAX.patch
c614235c98426a60d484203b47c44643833496de9864f2f6b1bedec206de33231878799d0b16ad2462c7ed2920cd0d8f9fd41fd7b1fff5b644e8be4b31ed815d  tunefs-remove-op_query.patch
a4b202ea3518f766e1b43b0acb1acc961d5c4d9d6792eaa77d64a07f97050be090e0233509b34fe9553328ec0e85c4735984a7009f6dc8b8325350e3525158d7  fix-sysmacros.patch
f10683473cff8f5c3513b80ac872e40b41d742338e17fe594558a033a6f7729debaf38129493742166a8b6d05b7ecc3ee7b4605eb7b2c22452caeeaaa2451ac8  enable-format-warnings.patch
07fed8c513da4c8f2d4a79cc9107e8c97fa38ea91ed28aea2cbb2916af37a0e5887e767b47d8a5c18b7d0aafd064979abf0b6faef7622e2aebba7d72a67dc5fe  fix-implicit-basename.patch
"
